package servlet_casa;

import java.io.IOException;
import java.util.ArrayList;


import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dao_casa.GestoreCasa;


/**
 * Servlet implementation class homePage
 */
@WebServlet("/homePage")
public class homePage extends HttpServlet {
	private static final long serialVersionUID = 1L;
       private GestoreCasa gestore=new GestoreCasa();
       private ArrayList<bean.Casa> casa;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		RequestDispatcher rd;
		HttpSession session=request.getSession(true);
		bean.Utente utente=(bean.Utente)session.getAttribute("utente");
		try{
		this.casa=gestore.getCase(utente);
		if(this.casa.size()>0){
			
			session.setAttribute("listaCase", this.casa);
			rd=request.getRequestDispatcher("/homePage.jsp");
			rd.forward(request, response);
		}
		else
			response.sendRedirect("configurazioneCasa.jsp");
		
	}catch(NullPointerException e){
		response.sendRedirect("login.jsp");
	}
	}
}
